package api

import (
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/Wefore/src/dbops"
	"gitee.com/DengAnbang/Wefore/src/fun"
	"gitee.com/DengAnbang/goutils/httpUtils"
	"net/http"
)

/**
* showdoc
* @catalog 接口文档/消息相关
* @title 消息查询
* @description 消息查询
* @method socket type=701
* @url /pc/message/select
* @param userId 必选 string 用户id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]MessageBean}
* @remark 最后修改时间:2018.12.07 10.30
* @number 1
 */
func MessageSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	messageBean, err := dbops.MessageSelect(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(messageBean)
}
func MessageSelectSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	messageBean, err := dbops.MessageSelect(userId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(messageBean)
}

/**
* showdoc
* @catalog 接口文档/消息相关
* @title 消息已读
* @description 消息已读
* @method socket type=702
* @url /pc/message/read
* @param messageId 必选 string 消息的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"操作成功"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 2
 */
func MessageReadHttp(_ http.ResponseWriter, r *http.Request) error {
	messageId := httpUtils.GetValueFormRequest(r, "messageId")
	err := dbops.MessageRead(messageId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("操作成功")
}
func MessageReadSocket(parameters map[string]interface{}) error {
	messageId := fun.GetString(parameters, "messageId")
	err := dbops.MessageRead(messageId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("操作成功")
}

/**
* showdoc
* @catalog 接口文档/消息相关
* @title 消息删除
* @description 消息删除
* @method socket type=703
* @url /pc/message/delete
* @param messageId 必选 string 消息的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"删除成功"}
* @remark 最后修改时间:2018.12.07 10.30
* @number 3
 */
func MessageDeleteHttp(_ http.ResponseWriter, r *http.Request) error {
	messageId := httpUtils.GetValueFormRequest(r, "messageId")
	err := dbops.MessageDelete(messageId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}
func MessageDeleteSocket(parameters map[string]interface{}) error {
	messageId := fun.GetString(parameters, "messageId")
	err := dbops.MessageDelete(messageId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("操作成功")
}
